package org.lib.eshello.news.entity;

import java.util.Date;

import org.springframework.data.annotation.Id;
import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.FieldType;
import org.springframework.data.elasticsearch.annotations.Setting;

import lombok.Data;

/**
 * 新闻
 * @author ben
 * @date 2021-09-01 13:46:53 CST
 */
// 方式0：初体验
@Document(indexName = "news")
// 方式1
//@Setting(shards = 2, replicas = 2, refreshInterval = "2s", indexStoreType = "mmapfs")
// 方式2
//@Setting(settingPath = "indices/news.setting.json")
// 方式3: 混合1、2，结果-以json文件为准
//@Setting(shards = 3, replicas = 3, refreshInterval = "3s", indexStoreType = "mmapfs", 
//	settingPath = "indices/news.setting.json")
// 同前一个
//@Setting(settingPath = "indices/news.setting.json", 
//	shards = 3, replicas = 3, refreshInterval = "3s", indexStoreType = "mmapfs")
// 使用sort*属性
// 已测试：类型 FieldType.Auto、FieldType.Text无法用来做排序
//@Setting(
//	sortFields = { "id", "title" },
//	sortOrders = {Setting.SortOrder.asc, Setting.SortOrder.asc}
// useServerConfiguration测试1
// 奇怪，settingPath的配置生效了！
//@Setting(useServerConfiguration = true,
//	shards = 3, replicas = 3, refreshInterval = "3s", indexStoreType = "mmapfs",
//	settingPath = "indices/news.setting.json",
//	sortFields = { "id", "title" },
//	sortOrders = {Setting.SortOrder.asc, Setting.SortOrder.asc},
//	sortModes = {Setting.SortMode.min, Setting.SortMode.max}
//)
// useServerConfiguration测试2 去掉settingPath
// 各个字段的配置没有生效
@Setting(useServerConfiguration = true,
	shards = 3, replicas = 3, refreshInterval = "3s", indexStoreType = "mmapfs",
	sortFields = { "id", "title" },
	sortOrders = {Setting.SortOrder.asc, Setting.SortOrder.asc},
	sortModes = {Setting.SortMode.min, Setting.SortMode.max}
)
@Data
public class News {

	protected News() {
	}
	
	/**
	 * 构造函数
	 * @param title
	 * @param url
	 * @param postTime
	 * @param source
	 * @param contentText
	 * @param contentHtml
	 */
	public News(String title, String url, Date postTime, String source, String contentText, String contentHtml) {
		this.title = title;
		this.url = url;
		this.postTime = postTime;
		this.source = source;
		this.contentText = contentText;
		this.contentHtml = contentHtml;
	}
	
	@Id
	@Field(type=FieldType.Keyword)
	private String id;

	/**
	 * 标题
	 */
	@Field(type=FieldType.Keyword)
	private String title;
	/**
	 * url
	 */
	private String url;
	/**
	 * 发布时间
	 */
	private Date postTime;
	
	/**
	 * 新闻来源
	 */
	private String source;

	/**
	 * 内容：文本
	 */
	private String contentText;
	
	/**
	 * 内容：HTML
	 */
	private String contentHtml;
	
}
